package com.elock.dao;

import org.springframework.stereotype.Repository;

import com.elock.base.core.dao.impl.DaoCenter;
import com.elock.base.core.util.ConvertUtil;
import com.elock.base.core.util.ExceptionUtil;
import com.elock.entity.SystemParameter;

/**
 * Dao - 系统参数
 * @author 仁德
 */
@Repository("systemParameterBaseDao")
public class SystemParameterBaseDao extends DaoCenter {

	public String getValue(Long companyInfoId, String code) {

		if (ConvertUtil.isEmpty(companyInfoId)) {
			ExceptionUtil.throwDaoException("value is empty!");
		}

		String sql = "select value from system_parameter where code = ? and company_info_id = ?";
		String value = getNativeDao().findString(sql,
				new Object[] { code, companyInfoId });

		return value;
	}

	public SystemParameter getAdminParam(String code) {

		String sql = "select * from system_parameter where company_info_id is null and code='"
				+ code
				+ "'";
		SystemParameter adminParamter = getNativeDao().findSingleManaged(sql,
				null,
				SystemParameter.class);
		return adminParamter;
	}
}